package com.example.wc.logindemo;

import android.content.Intent;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.widget.RadioGroup;

import com.example.wc.logindemo.MyServiceDemo.MyService;

/**
 * Created by hui on 2017/2/17.
 */

public class BlogsListActivity extends SingleFragmentActivity {

    private RadioGroup mRadioGroup;
    private Fragment mFragment;
    private Fragment mBlogsListFragment;
    private Fragment mQuestionFragment;
    private Fragment mMineFragment;
    private FragmentManager fm;

    @Override
    protected Fragment createFragment() {
        mRadioGroup = (RadioGroup) findViewById(R.id.fragment_radio_group);
        fm = getSupportFragmentManager();
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {

                switch (checkedId){
                    case R.id.blogs_radio_button :
                        if(mBlogsListFragment == null){
                            mFragment = new BlogsListFragment();
                            mBlogsListFragment = mFragment;
                        }
                        mFragment = mBlogsListFragment;
                       break;
                    case R.id.qa_radio_button :
                        if(mQuestionFragment == null){
                            mFragment = new QuestionFragment();
                            mQuestionFragment = mFragment;
                        }
                        mFragment = mQuestionFragment;
                        break;
                    case R.id.mine_radio_button :
                        if(mMineFragment == null){
                            mFragment = new MineFragment();
                            mMineFragment = mFragment;
                        }
                        mFragment = mMineFragment;
                        break;
                }
                fm.beginTransaction()
                        .replace(R.id.fragment_container, mFragment)
                        .commit();
            }
        });

        mFragment = new BlogsListFragment();
        mBlogsListFragment = mFragment;
        return mFragment;

    }

    @Override
    public void onDestroy(){
        super.onDestroy();

    }

}
